const mongoose = require('mongoose');
// 设定表规则
var userSchema = new mongoose.Schema({
    username: {
        type: String,
        required: ['true', '用户名不能为空']
    },
    password: {
        type: String,
        required: ['true', '密码不能为空'],
    },
    pic: {
        type: String
    },
    age: {
        type: Number,
        min: [18, '年龄不能小于18'],
        max: [100, '年龄不能大于100']
    },
    sex: {
        type: String,
        enum: {
            values: ['男', '女', '保密'],
            message: '请如实填写'
        }
    },
    address: {
        type: String
    },
    createtime: {
        type: Date,
        default: Date.now()
    }
});

// 创建表
// const User = mongoose.model('user', userSchema, 'user');
// mongoose添加表的规则是s,表名后面会以s为结尾
const User = mongoose.model('user', userSchema);

module.exports = User;